<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>微信配置</title>
    <link type="text/css" rel="stylesheet" th:href="@{${skinPath} + '/css.css'}"/>
    <script th:src="@{/inc/common.js}"></script>
    <script th:src="@{/js/jquery-1.9.1.min.js}"></script>
    <script th:src="@{/js/jquery-migrate-1.2.1.min.js}"></script>
    <script th:src="@{/js/jquery-alerts/jquery.alerts.js}" type="text/javascript"></script>
    <script th:src="@{/js/jquery-alerts/cws.alerts.js}" type="text/javascript"></script>
    <link th:href="@{/js/jquery-alerts/jquery.alerts.css}" rel="stylesheet" type="text/css" media="screen"/>
    <link th:href="@{/js/jquery-showLoading/showLoading.css}" rel="stylesheet" media="screen" />
    <script type="text/javascript" th:src="@{/js/jquery-showLoading/jquery.showLoading.js}"></script>
    <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
    <link rel="stylesheet" th:href="@{/js/layui/css/layui.css}" media="all">
</head>
<body>
<TABLE cellSpacing=0 cellPadding=0 width="100%">
    <TBODY>
    <TR>
        <TD class="tdStyle_1">微信配置</TD>
    </TR>
    </TBODY>
</TABLE>
<br>

<table width="100%" class="tabStyle_1 percent80" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td colspan="3" class="tabStyle_1_title">配置管理</td>
    </tr>

    <tr th:each="ary1 : ${ary1s}">

        <form method="post" th:id="${ary1.formNumber}" th:name="${ary1.formNumber}" >
<!--            <form method="post" th:id="${ary1.formNumber}" th:name="${ary1.formNumber}" th:data-form-id="${ary1.k}">-->

            <td width='52%'><input type="hidden" name="name" th:value="${ary1.name}"/>
                &nbsp;[[${ary1.desc}]]
            </td>
            <td width='34%'>
                <th:block th:if="${ary1.type1}">
                    <select th:id="'attr' +${ary1.k}" name="value">
                        <option value="true">
                            是
                        </option>
                        <option value="false">
                            否
                        </option>
                    </select>
                    <script>
                        $('[[${ary1.attr}]]').val("[[${ary1.value}]]");
                    </script>
                </th:block>
                <th:block th:if="${ary1.type2}">
                    <select th:id="'attr' +${ary1.k}" name="value">
                        <option value="1">系统帐户</option>
                        <option value="2">邮箱</option>
                        <option value="3">手机号</option>
                        <option value="4">工号</option>
                    </select>
                    <script>
                        $('[[${ary1.attr}]]').val('[[${ary1.relateVal}]]');
                    </script>
                </th:block>
                <th:block th:if="${ary1.type3}">
<!--                    <th:block th:unless="${ary1.type3}">-->
                    <th:block th:if="${ary1.type4}">
                        <input type=text th:value="${ary1.value}" name="value" size=30>
                    </th:block>
                    <th:block th:if="${!ary1.type1 && !ary1.type2 && ary1.type3 && !ary1.type4}">

                        <th:block th:if="${ary1.name} == 'isSyncWxToOA'">
                            <select th:id="'attr' +${ary1.k}" name="value">
                                <option th:each="aryOpt1 : ${ary1.aryOpts1}" th:value="${aryOpt1.aryOpts0}" th:text="${aryOpt1.aryOpts1}">
                                </option>
                            </select>
                        </th:block>
                        <th:block th:if="${ary1.name} == 'isUserIdUseMobile'">
                            <select th:id="'attr' +${ary1.k}" name="value">
                                <option th:each="aryOpt2 : ${ary1.aryOpts2}" th:value="${aryOpt2.aryOpts0}" th:text="${aryOpt2.aryOpts1}">
                                </option>
                            </select>
                        </th:block>
                        <th:block th:if="${ary1.name} ==  'wxMiniLoginMode'">
                            <select th:id="'attr' +${ary1.k}" name="value">
                                <option th:each="aryOpt2 : ${ary1.aryOpts2}" th:value="${aryOpt2.aryOpts0}" th:text="${aryOpt2.aryOpts1}">
                                </option>
                            </select>
                        </th:block>

                        <script>
                            $(function () {
                                $('[[${ary1.attr}]]').val('[[${ary1.value}]]');
                            })
                        </script>
                    </th:block>
                </th:block>
            </td>

            <td width="14%" align="center">
<!--                <input class="btn btn-default" type="submit" name='edit' value='修改' />-->
<!--                <input class="btn btn-default" type="button" name='edit' value='修改' th:attr="onclick=|handleSumbit('${ary1.formNumber}')|"/>-->
                <input class="btn btn-default" type="button" name='edit' value='修改' th:attr="onclick=|handleSumbit('${ary1.formNumber}')|"/>

            </td>

        </form>
    </tr>
</table>

<table th:each="ary2 : ${ary2s}">

<form th:id="'form'+${ary2.agentId}" method="post" th:data-form-id="'form'+${ary2.agentId}"  th:action="@{'/config_weixin?op=setAgent&amp;agentId=' +  ${ary2.agentId}}">
<!--    <form th:id="'form'+${ary2.agentId}" method="post" th:data-form2-id="'form'+${ary2.agentId}" th:action="@{'/config_weixin?op=setAgent&amp;agentId=' +  ${ary2.agentId}}"-->
<!--          enctype="multipart/form-data">-->
    <table width="100%" class="tabStyle_1 percent80" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td colspan="2" class="tabStyle_1_title">应用管理</td>
        </tr>
        <tr>
            <td>应用ID</td>
            <td><input id="agentId" name="agentId" th:value="${ary2.agentId}"/>
                <input id="oldAgentId" name="oldAgentId" type="hidden" th:value="${ary2.agentId}"/></td>
        </tr>
        <tr>
            <td>应用名称</td>
            <td><input id="agentName" name="agentName" th:value="${ary2.agentName}"/></td>
        </tr>
        <tr>
            <td>应用secret</td>
            <td><input id="secret" name="secret" th:value="${ary2.secret}" style="width:400px;"/></td>
        </tr>
        <tr>
            <td>应用主页</td>
            <td><input id="homeUrl" name="homeUrl" th:value="${ary2.homeUrl}" style="width:400px;"/></td>
        </tr>
        <tr>
            <td>应用LOGO</td>
            <td width="84%">
                <input id="media" name="media" type="file"/><span>&nbsp;[[${ary2.text}]]</span>

            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
<!--                <input class="btn" type="button" id="btnSetApp" value="确定" th:attr="onclick=|handleSumbit('${ary2.formNumber}', true)|"/>-->
                <input class="btn btn-default" type="button" id="btnSetApp" value="确定" th:attr="onclick=|handleSumbit('${ary2.formNumber}',true)|"/>

            </td>
        </tr>
    </table>
</form>
</table>

</body>
<script th:inline="javascript">
    function handleSumbit(formId, isSetAgent) {
        //var params = $("#" + formId).serialize();
        if (isSetAgent) {
            var formData = new FormData($('#' + formId)[0]);

            // var form = submit.closest('form');
            // // 使用data属性来获取表单ID的后缀
            // var formIdSuffix = form.getAttribute('data-form-id');
            // // 构造完整的表单ID并提交
            // var formId = 'form' + formIdSuffix;
            // var formData = $('#' + formId).serialize(); // 序列化对应表单的数据

            $.ajax({
                url: "../wx/admin/configAgent",
                dataType: 'json',// 服务器返回json格式数据
                type: 'post',// HTTP请求类型
                data: formData,
                processData: false,
                contentType: false,
                beforeSend: function (XMLHttpRequest) {
                    $('body').showLoading();
                },
                complete: function (XMLHttpRequest, status) {
                    $('body').hideLoading();
                },
                success: function (data) {
                    layer.msg(data.msg, {
                        offset: '6px'
                    });
                },
                error: function (xhr, type, errorThrown) {
                    console.log(type);
                }
            });
            return;
        }

        // var form = submit.closest('form');
        // // 使用data属性来获取表单ID的后缀
        // var formIdSuffix = form.getAttribute('data-form-id');
        // // 构造完整的表单ID并提交
        // var formId = 'form' + formIdSuffix;
        // var formData2 = $('#' + formId).serialize(); // 序列化对应表单的数据


        var params = $("#" + formId).serialize();
        $.ajax({
            type: "post",
            url: "../wx/admin/configWxWork",
            contentType:"application/x-www-form-urlencoded; charset=UTF-8",
            // contentType: false,
            data: params,
            dataType: "json",
            beforeSend: function(XMLHttpRequest){
                $('body').showLoading();
            },
            success: function(data, status) {
                layer.msg(data.msg, {
                    offset: '6px'
                });
            },
            complete: function(XMLHttpRequest, status){
                $('body').hideLoading();
            },
            error: function(XMLHttpRequest, textStatus){
                // 请求出错处理
                alert(XMLHttpRequest.responseText);
            }
        });
    }
    // layer.confirm('您确定要初始化全部表么？', {icon: 3, title: '提示'}, function (index) {
    //     layer.close();
    // $('.btn btn-default').click(function(e) {
    //
    //     e.preventDefault();
    //     var form = submit.closest('form');
    //     // 使用data属性来获取表单ID的后缀
    //     var formIdSuffix = form.getAttribute('data-form-id');
    //     // 构造完整的表单ID并提交
    //     var formId = 'form' + formIdSuffix;
    //     var formData = $('#' + formId).serialize(); // 序列化对应表单的数据
    //     console.log("formData:",formData);
    //
    //
    //
    //         $.ajax({
    //             url: "../wx/admin/configAgent",
    //             dataType: 'json',// 服务器返回json格式数据
    //             type: 'post',// HTTP请求类型
    //             data: formData,
    //             processData: false,
    //             contentType: false,
    //             beforeSend: function (XMLHttpRequest) {
    //                 $('body').showLoading();
    //             },
    //             complete: function (XMLHttpRequest, status) {
    //                 $('body').hideLoading();
    //             },
    //             success: function (data) {
    //                 console.log("formData:", formData);
    //                 layer.msg(data.msg, {
    //                     offset: '6px'
    //                 });
    //             },
    //             error: function (xhr, type, errorThrown) {
    //                 console.log(type);
    //             }
    //         });
    //         return;
    //     })
    // });
</script>
</html>